﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using NhaThuocOnline.Entities;
using NhaThuocOnline.Repositories;
using NhaThuocOnline.ViewModels;

namespace NhaThuocOnline.Service
{
    public class BacSiService
    {
        public void InsertOrUpdate(ViewModelsBacSi bacsi)
        {
            var enBacSi = Mapper.Map<ViewModelsBacSi, BacSi>(bacsi);
            using (BacSiRepository reBacSi = new BacSiRepository())
            {
                reBacSi.InsertOrUpdate(enBacSi);
                reBacSi.Save();
            }
        }
        public void Delete(int id)
        {
            using (BacSiRepository repo = new BacSiRepository())
            {
                repo.Delete(id);
                repo.Save();
            }
        }
        public List<ViewModelsBacSi> GetAll()
        {
            using (BacSiRepository repo = new BacSiRepository())
            {
                return Mapper.Map<List<BacSi>, List<ViewModelsBacSi>>(repo.All.ToList());
            }
        }
        public ViewModelsBacSi GetBacSiById(int id)
        {
            using (BacSiRepository repo = new BacSiRepository())
            {
                return Mapper.Map<BacSi, ViewModelsBacSi>(repo.All.Where(bs => bs.Id == id).FirstOrDefault());
            }
        }
    }
}
